<template>
	<view class="container">
		<view class="tit">
			<text>银行卡</text>
			<view class="right">
				<text v-if="!card" @click="toCard">添加银行卡</text>
				<text v-if="card" @click="toCard">
					<text class="bank">{{bank_name}}</text>
					<text class="separate">|</text>
					<text class="card">{{bank_card}}</text>
				</text>
				<image src="../../../static/img/detail/right.png" mode="widthFix"></image>
			</view>
		</view>

		<view class="ipt">
			<view class="title">
				<text>提现金额</text>
				<text class="tixin" @click="record('/pages/agent/user/record_tixian')">提现记录</text>
			</view>
			<view class="money">
				<text>￥</text>
				<input type="number" value="" placeholder="请输入提现金额" v-model="money" placeholder-style="font-size:32upx" />
			</view>

			<view class="bottom">
				<text>可提现金额：￥{{money_ke}}</text>
				<text class="tixin" @click="all">全部提现</text>
			</view>
		</view>

		<view class="btn">
			<button type="default" @click="submit">确认提现</button>
		</view>

	</view>
</template>

<script>
	import {
		bankDetail,
		cash
	} from '../../../api/api.js'
	export default {
		data() {
			return {
				card: true,
				money: '',
				money_ke: '1000.00',
				bank_name:'',
				bank_card:''
			}
		},
		onLoad() {
			this.money_ke = uni.getStorageSync('user').money
		},
		onShow() {
			this.getBankInfo()
		},
		methods: {
			getBankInfo() {
				bankDetail().then(res => {
					console.log(res)
					if (res.data) {
						this.card = true
						this.bank_name = res.data.bank
						this.bank_card = res.data.bank_card.substring(res.data.bank_card.length-4,res.data.bank_card.length)
					} else {
						this.card = false
					}
				})
			},
			toCard() {
				uni.navigateTo({
					url: '/pages/agent/user/card'
				})
			},
			all() {
				this.money = this.money_ke
			},
			record(url) {
				uni.navigateTo({
					url: url
				})
			},
			submit() {
				if (!this.card) {
					uni.showToast({
						icon: 'none',
						title: '请先添加银行卡信息'
					})
					return
				}
				
				if (!this.money) {
					uni.showToast({
						icon: 'none',
						title: '请输入可提现金额'
					})
					return
				}
				
				if(Number(this.money) > Number(this.money_ke)){
					uni.showToast({
						icon: 'none',
						title: '超过可提现最大金额'
					})
					return
				}
				
				if(this.money == 0){
					uni.showToast({
						icon: 'none',
						title: '提现金额请大于0'
					})
					return
				}
				
				cash({
					money:this.money
				}).then(res=>{
					console.log(res)
					if(res.code == 1){
						uni.showModal({
							title: '提示',
							content: '申请提现成功，请等工作人员审核',
							showCancel: false,
							success: function(res) {
								uni.reLaunch({
									url: '/pages/agent/user'
								})
							}
						})
					}
				})
				
				
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		width: 100%;
		height: 100%;
		background-color: #f6f6f6;
	}

	.tit {
		width: calc(100% - 60upx);
		padding: 0 30upx;
		height: 100upx;
		background-color: #FFFFFF;
		display: flex;
		justify-content: space-between;
		align-items: center;

		text {
			font-size: 30upx;
		}

		.right {
			display: flex;
			align-items: center;

			// text{
			// 	margin-right: 30upx;
			// }
			text {
				text {
					margin-left: 10upx;
				}
			}

			image {
				width: 20upx;
				margin-left: 30upx;
			}
		}

	}

	.ipt {
		margin-top: 10upx;
		width: calc(100% - 60upx);
		padding: 0 30upx;
		background-color: #FFFFFF;
		font-size: 30upx;

		.title,
		.bottom {
			width: 100%;
			height: 100upx;
			line-height: 100upx;
			display: flex;
			justify-content: space-between;

			.tixin {
				color: #3eb9fe;
			}
		}

		.bottom {
			margin-top: 10upx;
			color: #999999;
		}

		.money {
			display: flex;
			align-items: center;
			height: 80upx;
			font-size: 40upx;
			border-bottom: 1upx solid #ECECEC;

			input {
				height: 100%;
				margin-left: 20upx;
				font-size: 40upx;
			}
		}
	}

	.btn {
		width: calc(100% - 60upx);
		height: 90upx;
		margin: 50upx auto;
		overflow: hidden;
		border-radius: 45upx;

		button {
			width: 100%;
			height: 90upx;
			background-color: #3eb9fe;
			color: #FFFFFF;
		}
	}
</style>
